﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace QuickSearchAndSelect
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private SearchAndSelectViewModel viewModel = null;
        public MainWindow()
        {
            InitializeComponent();

            var myProducts = new List<Product>();
            myProducts.Add(new Product() { Name = "Asparagus" });
            myProducts.Add(new Product() { Name = "Broccoli" });
            myProducts.Add(new Product() { Name = "Chard" });
            myProducts.Add(new Product() { Name = "Dandelion" });
            myProducts.Add(new Product() { Name = "Endive" });
            myProducts.Add(new Product() { Name = "Fennel" });
            myProducts.Add(new Product() { Name = "Jicama" });
            myProducts.Add(new Product() { Name = "Kale" });
            myProducts.Add(new Product() { Name = "Lettuce" });
            myProducts.Add(new Product() { Name = "Potatoes" });
            myProducts.Add(new Product() { Name = "Rhubarb" });
            viewModel = searchControl.ViewModel;
            viewModel.Source = myProducts;
            viewModel.SelectedIndex = 0;

            this.searchControl.ListBoxKeyDown += ListBoxKeyDown;
        }

        private void ListBoxKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Up)
            {
                viewModel.SelectedIndex--;
                e.Handled = true;
            }
            else if (e.Key == Key.Down)
            {
                viewModel.SelectedIndex++;
                e.Handled = true;
            }
            else if (e.Key == Key.Home)
            {
                viewModel.SelectedIndex = 0;
                e.Handled = true;
            }
            else if (e.Key == Key.End)
            {
                //viewModel.SelectedIndex = Products.Items.Count - 1;
                e.Handled = true;
            }
        }
    }
}
